package com.ruoyi.supplier.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.supplier.domain.SupBanner;
import com.ruoyi.supplier.service.ISupBannerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * banner信息Controller
 * 
 * @author zjf
 * @date 2025-11-05
 */
@RestController
@RequestMapping("/banner")
public class SupBannerController extends BaseController
{
    @Autowired
    private ISupBannerService supBannerService;

    /**
     * 查询banner信息列表
     */
    @RequiresPermissions("system:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(SupBanner supBanner)
    {
        startPage();
        List<SupBanner> list = supBannerService.selectSupBannerList(supBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner信息列表
     */
    @RequiresPermissions("system:banner:export")
    @Log(title = "banner信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupBanner supBanner)
    {
        List<SupBanner> list = supBannerService.selectSupBannerList(supBanner);
        ExcelUtil<SupBanner> util = new ExcelUtil<SupBanner>(SupBanner.class);
        util.exportExcel(response, list, "banner信息数据");
    }

    /**
     * 获取banner信息详细信息
     */
    @RequiresPermissions("system:banner:query")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(supBannerService.selectSupBannerByBannerId(bannerId));
    }

    /**
     * 新增banner信息
     */
    @RequiresPermissions("system:banner:add")
    @Log(title = "banner信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupBanner supBanner)
    {
        return toAjax(supBannerService.insertSupBanner(supBanner));
    }

    /**
     * 修改banner信息
     */
    @RequiresPermissions("system:banner:edit")
    @Log(title = "banner信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupBanner supBanner)
    {
        return toAjax(supBannerService.updateSupBanner(supBanner));
    }

    /**
     * 删除banner信息
     */
    @RequiresPermissions("system:banner:remove")
    @Log(title = "banner信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(supBannerService.deleteSupBannerByBannerIds(bannerIds));
    }
}
